unit cataurus.verwaltung.admin.wizNewProject;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, JvWizard, JvWizardRouteMapNodes, Mask,
  JvExMask, JvToolEdit, JvExControls, IdExplicitTLSClientServerBase, IniFiles;

type
  TfrWizProjektNeu = class(TForm)
    JvWizard1: TJvWizard;
    JvWizardInteriorPage1: TJvWizardInteriorPage;
    JvWizardInteriorPage2: TJvWizardInteriorPage;
    Label1: TLabel;
    eProjektname: TEdit;
    Label2: TLabel;
    eProjektbeschreibung: TEdit;
    eNWNDir: TJvDirectoryEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    eFTPHost: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    JvWizardWelcomePage1: TJvWizardWelcomePage;
    JvWizardRouteMapNodes1: TJvWizardRouteMapNodes;
    JvWizardInteriorPage3: TJvWizardInteriorPage;
    IdFTP1: TIdFTP;
    Button1: TButton;
    eFTPPort: TEdit;
    Label8: TLabel;
    eFTPBenutzer: TEdit;
    eFTPPasswort: TEdit;
    eVerz: TEdit;
    procedure JvWizard1FinishButtonClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure IdFTP1Connected(Sender: TObject);
  private
    { Private-Deklarationen }
    AppIni : TIniFile;
  public
    { Public-Deklarationen }
  end;

function Execute(AppIni : TInifile) : string;

implementation

uses cataurus.verwaltung.admin.typeproject;

{$R *.dfm}

function Execute(AppIni : TInifile) : string;
var
  frWizProjektNeu: TfrWizProjektNeu;
begin
  frWizProjektNeu := TfrWizProjektNeu.Create(nil);
  try
    frWizProjektNeu.AppIni := AppIni;
    if frWizProjektNeu.ShowModal = mrOK
    then
    begin
      result := frWizProjektNeu.eProjektname.Text;
    end;
  finally
    frWizProjektNeu.Free;
  end;
end;

procedure TfrWizProjektNeu.Button1Click(Sender: TObject);
begin
  IdFTP1.Host := eFTPHost.Text;
  IdFTP1.Port := StrToInt(eFTPPort.Text);
  IdFTP1.Account := eFTPBenutzer.Text;
  IdFTP1.Password := eFTPPasswort.Text;
  IdFTP1.Connect;
  IdFTP1.ChangeDir(eNWNDir.Text);
end;

procedure TfrWizProjektNeu.IdFTP1Connected(Sender: TObject);
begin
  ShowMessage('Test erfolgreich');
end;

procedure TfrWizProjektNeu.JvWizard1FinishButtonClick(Sender: TObject);
var
  Project : TProject;
  ProjectFile : string;
  iAnzahl : integer;
begin
  IdFTP1.Disconnect;
  ProjectFile := ExtractFilePath(Application.ExeName)+ eProjektname.Text +'.ini';

  iAnzahl := AppIni.ReadInteger('Allgemein', 'Anzahl', 0);
  Inc(iAnzahl);

  AppIni.WriteInteger('Allgemein', 'Anzahl', iAnzahl);
  AppIni.WriteString('Projekt'+IntToStr(iAnzahl), 'Name', eProjektname.Text);

  Project := TProject.Create(ProjectFile, AppIni);
  try
    Project.ProjektName := eProjektname.Text;
    Project.Beschreibung := eProjektbeschreibung.Text;
    Project.Verzeichnis := eNWNDir.Text;
    Project.FTPDirectory := eVerz.Text;
    Project.FTPHost := eFTPHost.Text;
    Project.FTPPort := StrToInt(eFTPPort.Text);
    Project.FTPBenutzer := eFTPBenutzer.Text;
    Project.FTPPasswort := eFTPPasswort.Text;
  finally
    Project.Free;
  end;

end;

end.
